//
// Created by THE13 on 2024/2/5.
//

#ifndef CHICHIBOOM_UI_SIMLATOR_SDL2_INTERFACE_H
#define CHICHIBOOM_UI_SIMLATOR_SDL2_INTERFACE_H

#include <stdint.h>
#include <string.h>
#include <stdio.h>

#include "sdl2_font_buffer.h"
#include "st7789.h"

#define  SCREEN_HEIGHT ST7789_HEIGHT
#define  SCREEN_WIDTH ST7789_WIDTH

/* color const param*/
#define PALEVIOLET		0XDB92
#define LIGHTPINK		 0XFF9E
#define CRIMSON 		 0xD8A7
#define PINK        0xFE19
#define DGRAY       0x8410   
#define WHITE       0xFFFF
#define BLACK       0x0000
#define BLUE        0x001F
#define RED         0xF800
#define MAGENTA     0xF81F
#define GREEN       0x07E0
#define CYAN        0x7FFF
#define YELLOW      0xFFE0
#define GRAY        0X8410
#define BRED        0XF81F
#define GRED        0XFFE0
#define GBLUE       0X07FF
#define BROWN       0XBC40
#define BRRED       0XFC07
#define DARKBLUE    0X01CF
#define LIGHTBLUE   0X7D7C
#define GRAYBLUE    0X5458
#define LIGHTGREEN  0X841F
#define LGRAY       0XC618
#define LGRAYBLUE   0XA651
#define LBBLUE      0X2B12
#define SILVER      0XC618
#define DARKGRAY		0XAD55
#define PURPLE			0XF81F
/* draw mode config */
#define NORMAL 0
#define XOR 1
#define TRA 2

#define SDL2_DRAW_UPPER_RIGHT  0x01
#define SDL2_DRAW_UPPER_LEFT   0x02
#define SDL2_DRAW_LOWER_LEFT 	 0x04
#define SDL2_DRAW_LOWER_RIGHT  0x08
#define SDL2_DRAW_ALL (SDL2_DRAW_UPPER_RIGHT|SDL2_DRAW_UPPER_LEFT|SDL2_DRAW_LOWER_LEFT|SDL2_DRAW_LOWER_RIGHT)

#define LIGHT_MODE 0
#define DARK_MODE 1


/* math fun */
#define ABS(x) ((x) > 0 ? (x) : -(x))

typedef struct sdl2_struct
{
    /*以像素为单位显示用户的尺寸 display dimensions in pixel for the user, calculated in u8g2_update_dimension_common()  */
    uint8_t width;
    uint8_t height;
		uint8_t screen_mode;
		FontDefv2 font;
    uint8_t  mode;//颜色是否取反
    int bg_color;//背景颜色
    int draw_color;        /* 0: clear pixel, 1: set pixel, modified and restored by font procedures */
}sdl2_t;

/* sd2_buffer.cpp */
extern sdl2_t sdl2;
/* data buffer */
extern uint16_t disp_buf[SCREEN_HEIGHT][SCREEN_WIDTH];

/*==========================================*/
/* sdl2_line.c */
void draw_line(sdl2_t *sdl2,int16_t x0, int16_t y0, int16_t x1, int16_t y1);


/*==========================================*/
/* sdl2_hvline.c */
void sdl2_DrawHLine(sdl2_t *sdl2, int16_t x, int16_t y, uint16_t len);
void sdl2_DrawVLine(sdl2_t *sdl2, int16_t x, int16_t y, uint16_t len);
void sdl2_DrawHVLine(sdl2_t *sdl2, int16_t x, int16_t y, uint16_t len, uint8_t dir);

/*==========================================*/
/* sdl2_box.c */
void sdl2_DrawBox(sdl2_t *sdl2, int16_t x, int16_t y, uint16_t w, uint16_t h);
void sdl2_DrawFrame(sdl2_t *sdl2, int16_t x, int16_t y, uint16_t w, uint16_t h);
void sdl2_DrawRBox(sdl2_t *sdl2, int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t r);
void sdl2_DrawRFrame(sdl2_t *sdl2, int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t r);
/*==========================================*/
/* sdl2_buffer.c */
int      XorColor(int color);
uint16_t TraColor(uint16_t color);
uint16_t sdl2_setPixBuffer(sdl2_t *sdl2,int x0,int y0);
void sdl2_setPencil(sdl2_t *sdl2,int draw_color,int bg_color);
void sdl2_cleanBuffer(void);
void sdl2_GradualCleanBuffer(void);
void sdl2_sendbuffer(void);
void sdl2_setMode(sdl2_t *sdl2,uint8_t mode);
void sdl2_DrawPixel_buffer(sdl2_t *sdl2,uint16_t x, uint16_t y);


/*==========================================*/
/* sdl2_font.c */
void sdl2_set_font(sdl2_t *sdl2,FontDefv2 font);
void sdl2_draw_float(sdl2_t *sdl2,int16_t x, int16_t y, float num);
void sdl2_draw_string(sdl2_t *sdl2,int16_t x, int16_t y, const char *str);
void sdl2_draw_float(sdl2_t *sdl2,int16_t x, int16_t y, float num);
void sdl2_draw_cn(sdl2_t *sdl2,int16_t x, int16_t y,FontDefv2 font);

/*==========================================*/
/* sdl2_circle.c */
void sdl2_DrawCircle(sdl2_t *sdl2,int16_t x, int16_t y, uint16_t rad, uint8_t option);
void sdl2_DrawDisc(sdl2_t *sdl2, int16_t x, int16_t y, uint16_t rad, uint8_t option);
void sdl2_DrawEllipse(sdl2_t *sdl2, int16_t x0, int16_t y0, int16_t rx, int16_t ry, uint8_t option);
void sdl2_DrawFilledEllipse(sdl2_t *sdl2, int16_t x0, int16_t y0, int16_t rx, int16_t ry, uint8_t option);

/*==========================================*/
/* sdl2_image.c */
void sdl2_DrawImage(int16_t x, int16_t y, int16_t w, int16_t h, const uint16_t *data);

//图片 自己的 水平扫描 16位真色彩  63%
extern const unsigned char gImage_fu[56456];//168x168   

extern const unsigned char gImage_setting[12800];//80x80
extern const unsigned char gImage_user[12800];
extern const unsigned char gImage_keyboard[12800];//USED
extern const unsigned char gImage_more[12800];//USED
extern const unsigned char gImage_chart[12800];//USED
extern const unsigned char gImage_ubuntu[12800];
#endif //CHICHIBOOM_UI_SIMLATOR_SDL2_INTERFACE_H
